package com.ruoyi.web.controller.market.account;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.AccountItemSpecial;
import com.ruoyi.account.service.IAccountItemSpecialService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.AccountItemSpecialWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机构账户信息Controller
 * 
 * @author ruoyi
 * @date 2023-07-28
 */
@Controller
@RequestMapping("/account/itemSpecial")
public class AccountItemSpecialController extends BaseController
{
    private String prefix = "account/itemSpecial";

    @Autowired
    private IAccountItemSpecialService accountItemSpecialService;

    @RequiresPermissions("account:itemSpecial:view")
    @GetMapping()
    public String itemSpecial()
    {
        return prefix + "/itemSpecial";
    }

    /**
     * 查询机构账户信息列表
     */
    @RequiresPermissions("account:itemSpecial:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountItemSpecial accountItemSpecial)
    {
        SysUser sysUser = getSysUser();
        if (!sysUser.isAdmin()){
            // 管理员可以查询所有的机构账户
            // 查询自己的机构信息
            accountItemSpecial.setOwnerId(sysUser.getUserId());
        }

        startPage();
        List<Map<String, Object>> mapList = accountItemSpecialService.selectAccountItemSpecialListMap(accountItemSpecial);
        mapList = new AccountItemSpecialWapper(mapList).wrap();
        return getDataTable(mapList);
    }



    /**
     * 新增机构账户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存机构账户信息
     */
    @RequiresPermissions("account:itemSpecial:add")
    @Log(title = "机构账户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccountItemSpecial accountItemSpecial)
    {
        return toAjax(accountItemSpecialService.insertAccountItemSpecial(accountItemSpecial));
    }

    /**
     * 修改机构账户信息
     */
    @RequiresPermissions("account:itemSpecial:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        AccountItemSpecial accountItemSpecial = accountItemSpecialService.selectAccountItemSpecialById(id);
        mmap.put("accountItemSpecial", accountItemSpecial);
        return prefix + "/edit";
    }

    /**
     * 修改保存机构账户信息
     */
    @RequiresPermissions("account:itemSpecial:edit")
    @Log(title = "机构账户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccountItemSpecial accountItemSpecial)
    {
        return toAjax(accountItemSpecialService.updateAccountItemSpecial(accountItemSpecial));
    }

    /**
     * 删除机构账户信息
     */
    @RequiresPermissions("account:itemSpecial:remove")
    @Log(title = "机构账户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accountItemSpecialService.deleteAccountItemSpecialByIds(ids));
    }
}
